<!doctype html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>修改</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../css/mui.css" rel="stylesheet" />
		<link href="../../css/list.css" rel="stylesheet" />
		 <script src="../../js/app.js"></script>
		 <link href="../../css/style.css" rel="stylesheet" />
		 <link href="../../css/icons-extra.css" rel="stylesheet"/>
<!--<link rel="stylesheet" href="css/message.css" type="text/css" />-->
		 		<!--<script src="../js/jquery-3.3.1.js"></script>-->
		 		<style type="text/css">
		 			.mui-content{
		 				margin-bottom: 40px;  
		 			}
		 			/*body {font-family: sans-serif;}*/
		 			#show_messagea li{
		 				background: #fff;
		 		/*		padding:5px 5px 0 5px;*/
		 			}
		 			#show_messagea{
		 				background: #FAFAFA;
		 			/*#show_messagea img{
		 				/*background: #FAFAFA;*/
		 				/*padding:5px 5px 0 5px;*/
		 				
		 			}
		 			.mui-media-body{
		 				
		 				/*background: #F3F3F3;*/
		 				/*padding:5px 5px 0 5px;*/
		 				/*border-radius:10px;
		 				font-size: 16px;
		 				line-height:120%;
		 				margin : 0px 2px 2px 5px;*/
		 			}
		 			.p1{
		 				color: #000000;
		 				font-size: 20px;
		 				/*letter-spacing:0.1em;*/
		 				/*text-indent:2em;*/
		 				/*padding:0 0.1em;*/
		 				padding: 3px;
		 			}
		 			.p2{
		 				/*margin : 0px 2px 10px 55px;*/
		 				/*background: #EFEFF4;*/
		 				padding:0 0px 0 62px;
		 				border-radius:5px;
		 			}
table,tr,td,th{

padding: 0;

margin: 0;

}

table{

width: 100%;

border-color: #ccc;

}

table tr{

/*line-height: 30px;*/
/**/
border-color: #ccc;

}

table th,table td{
	 padding: 8px;
border-width: 1px;
 border-style: solid;
 border-color: #999999;
/*text-align: center;*/

/*border-color: #ccc;*/

}

		 			/*tr:nth-child(odd){background:#F0F8FF;}*/
table tr:nth-child(even){
background: #ccc;
}
		 			a{ text-decoration:none;
    color:#222222;}

/*小盒子内容区的样式，display:inline-block：实现 效果*/
#con{
	margin: 1px;
}
#con .pic{ border-radius:1px;float:left; min-height:100px;box-shadow:2px 2px 6px #b5b5b5;line-height:1.2;margin: 5px;padding:2px;}
#con p{
	margin-bottom: 2px;
}
#con h5{padding:1px;margin-top: -2px;border-bottom:1px solid #ddd;}
#con h5 a{text-decoration:none;color:#999;}
.speak{
	/*输入框居中漂浮*/
position: fixed;
width:100%;
top:30%;
/*left:50%;*/
margin: auto auto;
padding: 0 5px;
text-align: center;
		 			}
</style>
</head>
<header class="mui-bar mui-bar-nav">
    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
  <h1 class="mui-title">简历修改<span id="title"></span></h1>
</header>

		<div class="mui-content">
<div class="pic" style="width:80%;margin:0 auto;text-align:center" id="image"></div>
      <div id="neirong" class="mui-content-padded" style="text-align: center;"></div>
      <div id="picture"style="margin-left: 0;" ><span id="img" class="slide-box"></span><span><img onclick="imgup()" style="width:80px;" src="../../images/iconfont-tianjia.png"/></span></div>
      <!--输入框-->
    <div id="speak" class="speak" style="display:none;background: #DDDDDD;">
		<p id='speaktitle' style="margin:auto auto;font-size: 1.2em;color:#EC971F">请输入新内容</p>
		<textarea id="value" type="text"rows="6"placeholder="请输入"></textarea>
		<div style="margin-top: -24px;border-radius:5px;">
		<input id="pubish" style="font-size: 18px;margin: 2px 5px;padding:0 10px;float: right;" value="确认" type="submit">
		<input  style="font-size: 18px;margin: 2px 5px;float: right;padding:0 10px;" value="取消" type="submit" onclick="javascript:(document.getElementById('speak').style.display='none')">
		</div>
	</div>
</div>
<!--上传附件进度显示-->
<!--<input type="text" name="val" id="val" value="" />-->
<script src="../../js/mui.min.js"></script>
<script src="../../js/upload.js"></script>
<script type="text/javascript">
	mui.init();
	value=document.getElementById('value');
//			window.addEventListener('renovate', function(e){
//				//主图裁剪上传返回数据执行更新
//				alert(e.detail.image+e.detail.tid);
//				imageplay(e.detail.image,e.detail.tid);
////			  location.reload(); //刷新
//			  });
//	function image(tid,act,method,imgsrc,width,height) {
//		act=act||'resume';
//		method=method||'resume';
//		width=width||300;
//		height=height||300;
//		localStorage.image='{"tid":"'+tid+'","act":"up'+act+'","method":"'+method+'","src":"'+imgsrc+'","width":'+width+',"height":'+height+'}';
//		mui.openWindow('../../Plugin/image/image.html');
//	};
	//调用方式
	window.addEventListener('renovate', function(e){
		//裁剪后返回的64base图片显示在image标签下的img
		document.getElementById('image').getElementsByTagName('img')[0].src=e.detail.image;
				//主图裁剪上传返回数据执行更新
//			  location.reload(); //刷新
//					apptoken['type']='image',//修改的类型
                  	value.value=e.detail.image;//值
//                	apptoken['act']='modify'//修改
                  	modify(tid,'image');
//         upload(apptoken);//上传服务器
			  });
function image() {
		width=200;
		height=200;
		localStorage.image='{"src":"'+document.getElementById('image').getElementsByTagName('img')[0].src+'","width":'+width+',"height":'+height+'}';
		mui.openWindow('../../Plugin/image/base64.html');
};
   //发布回复输入框控制
function modifyinput(tid,key){
//	alert(tid+key);
	speaktitle=document.getElementById('speaktitle');
	value.value=document.getElementById(key).innerText;
	if(key=='password'){
		value.rows='1';//文本输入框显示的高度行数
		speaktitle.innerText='请输入新密码';
	}else{
		speaktitle.innerText='请输入新内容';
	}
	document.getElementById('speak').style.display='block';//显示输入框
	var tid=tid||'';
	var key=key ||'';
		document.getElementById('pubish').onclick=function(){
			document.getElementById('speak').style.display='none';//隐藏发布按钮
			modify(tid,key);
			}
} 


apptoken['tid']=tid;//获取详情id
apptoken['act']='detail';
mui.post(home.hos+'/resume/admin',apptoken,function(data){
//      		alert(data);
	if(isJSON(data)){
		result=JSON.parse(data);//获取信息
		jsonarrfor(result);//加载详情信息
//		_relation(result.relation,result.relation_id);//加载关联信息
//		list_comment(result.id);//加载评论信息
		}else{
			alert('页面加载失败，或不存在，请重新尝试');
			return false;
    	}
})
var type=64;//可不填。返回类型（file/64base）;
var imgnames='imgs';//img对应的name值
var upload=new uploadimg(imgsplay,type);//实例化类
function imgsplay(path){//两个参数path必填是图片路径，type=64可填，返回数据类型。默认不填返回图片源文件,64=返回64base压缩类型
if(type===64){//判断是否需要64base转码压缩
		var image = new Image();
			image.src = path;  
			image.onload = function(){
			var img_typearr=['jpeg','jpg','bmp','png'];//支持格式类型
			_type=upload.appendFile(img_typearr,path);//检查是否支持,返回false 或者后缀名
			if(_type){
			var is_type="image/jpeg";//压缩格式
			var ratio=0.9;//压缩质量
			var width=1080;//压缩后最长边距像素；
		    path = compress(image,width, ratio,is_type);//压缩图片转成64base后显示
		    img=document.getElementById('img');
		    apptoken['img']=path;
		    apptoken['act']='upimg';
		    mui.post(home.hos+'/resume/admin',apptoken,function(data){//获取关联数据
//		    	alert(data);
		    	if(isJSON(data)){
		    		var imgarr=JSON.parse(data);
				    var status=imgarr['status'] || '';
				    if(imgarr.status==200){
				    	 imgplay(imgarr.img,apptoken['tid']);//图片追加到html
				 		plus.ui.toast('上传成功');
				 	}else{
				 		plus.ui.toast('上传失败');
				 	}
		    	}else{
		    		alert('打开失败，请从新尝试');
		    		return false;
		    	}
		    
		})
			}
return false;}
}else{
	 alert('不支持的类型'+path);
}
};
function status(state){
	if(state==1){
	var status='<span style="color:#00EE00;">●</span><span style="border-radius:25px;border:2px solid #a1a1a1;padding:2px 5px">聊聊</span>';
}else{
	var status='<span style="color:red;">■</span><span style="border-radius:25px;border:2px solid #a1a1a1;padding:2px 5px">忙碌</span>';
}
document.getElementById('status').value=state;
document.getElementById('status').innerHTML=status;
}
function imageplay(image,tid){
	document.getElementById('image').innerHTML='<img onclick="image()" style="width:95%;" src="'+home.uploads+'/img/resume/min'+image+'" onerror="this.onerror=null;this.src=\'../../images/iconfont-tianjia.png\'" />';
}
function jsonarrfor(result){
	var dongtai="";
		if(!result.pic=='' || result.pic=='null'){
			rpic=result.pic.split(",");
//			classimg="imgx1";}
			var zhuchuang=""; 
			for(var ib=0;ib<rpic.length;ib++){

imgplay(rpic[ib],result.id)
   }

}
		var enclosure='文档资料(下载密码：<span id="password">'+result.password+'</span>)<div  style="width:100%;height:30px;border: 1px solid;margin-bottom:10px; background-color:rgb(240,240,240);border-radius:5px;" onclick="input()"><h5 id="inputdiv" style="width:100%;">添加文件:(支持后缀名pdf/ppt/doc/pptx/docx)</h5></div><input style="display:none" class="file" type="file" id="fileToUpload" onchange="getFilename()"><input type="button" onclick="uploadFile('+result.id+')" value="立即上传"><input type="button" onclick="modifyinput('+result.id+',\'password\')" value="重置密码">';
var birthday=new Date(parseInt(result.birthday) * 1000).format('yyyy年M月d日');
//形象头像
imageplay(result.image,result.id);
//document.getElementById('image').innerHTML='<img onclick="image('+result.id+',\'image\',\'resume\',this.src)" style="width:95%;" src="'+home.uploads+'/img/resume/'+result.image+'" onerror="this.onerror=null;this.src=\''+home.uploads+'/img/resume/'+result.image+'\'" />';
val='<li><br><h3>'+result.profession+':'+result.name+'</h3><p  style="background: transparent;">档期状态<span id="status" value="'+result.status+'"></span><br><input type="button" onclick="modify('+result.id+',\'status\')" value="切换状态" /></p><p><span>简介</span>[<span onclick="modifyinput('+result.id+',\'synopsis\')" style="color:red">修改+</span>]<br><span id="synopsis">'+result.synopsis+'</span></p><div class="list-head"></div><table><tr><td width="110px">合作方式</td><td>'+result.ways+'</td></tr><tr><td width="110px">生日</td><td>'+birthday+'</td></tr><tr><td width="110px">地区</td><td>'+result.region+'</td></tr><tr><td width="110px">特长</td><td>'+result.speciality+'</td></tr><tr><td width="110px">代表作品</td><td>'+result.opus+'</td></tr><tr><td>公司</td><td>'+result.company+'</td></tr><tr><td>毕业院校</td><td>'+result.school+'</td></tr><tr><th  colspan="2" style="text-align:center;color:red;" id="enclosure">'+enclosure+'</th></tr></table></div></li>';
//status(result.status);
document.getElementById('neirong').innerHTML=val;
status(result.status);
}

function imgdelete(img,tid){
	if (confirm("确定要删除这张图片吗？")) { 
	apptoken['tid']=tid;
	apptoken['img']=img;
	apptoken['act']='deleteimg';
	mui.post(home.hos+'/resume/admin',apptoken,function(data){//获取关联数据
//		alert(data);
	 	if(data==1){
	 		var tid=document.getElementById('con'+img);
			tid.parentNode.removeChild(tid);//窗口文档中删除图片div
	 		plus.ui.toast('删除成功');
	 	}else{
	 		plus.ui.toast('操作失败');
	 	}
	})
	 } 
    else { 
      plus.ui.toast('操作取消'); 
    } 
}

function delete_html(thisid){
	var tid=document.getElementById(thisid);
	tid.parentNode.removeChild(tid);//删除div
}

function imgplay(imgname,tid){//把图片追加到窗口
	html='<li class="pic" onclick="imgdelete(\''+imgname+'\',\''+tid+'\')" id="con'+imgname+'" style="max-width:100px;min-height:10px;padding:2px;position:relative" ><p style="position:absolute;text-align:center;border-radius:9px;color:#fff;line-height:1em;background:red;padding:3px">✖</p><img id="'+imgname+'" style="margin:0;width:100%;max-width:100px;"  src="'+home.uploads+'/img/resume/min'+imgname+'" onerror="this.onerror=null;this.src=\'../../images/logo.png\'"  /></li>';
//	document.getElementById("img").innerHTML+=html;
	appendChild("img",html,'1');
}
function imgup(){
	var cs=document.getElementById("img").getElementsByTagName("li");
		var maxnum=9-cs.length;//限制上传图片数量
		var lasnum=9-cs.length;
		if(lasnum<=0){
			alert('最多只能上传9张图片');
			return false;
		}
	var lasnum=maxnum-document.getElementsByName(imgnames).length;
	upload.addImage(maxnum,lasnum,'neirong');//图片img外层id
}




//修改组件
function modify(tid,type){
//	alert(JSON.stringify(apptoken));
//	return false;
	//k=键；act=修改方法，tid=主题id，type=修改类型；
	apptoken['k']=type||'';
	if(type=='synopsis' || type==''){//如果修改的页面是内容多行文本，将会替换换行符
	apptoken['v']=getFormatCode(value.value) ||'';
	}else{
		apptoken['v']=value.value ||'';
	}
	//状态切换
	if(type=='status'){
		var statu=document.getElementById('status');
		if(statu.value==1){
			apptoken['v']=2;
		}else{
			apptoken['v']=1;
		}
	}
	apptoken['tid']=tid||'';
	apptoken['act']='modify';
	mui.post(home.hos+'/resume/admin',apptoken,function(data){
//		alert(JSON.stringify(data));
		if(isJSON(data)){
			if(type=='status'){
				//如果修改的是状态
			status(apptoken['v']);	
			}else if(type=='image'){
				//如果修改的是图片
			document.getElementById(type).src=apptoken['v'];
			}else{
			document.getElementById(type).innerHTML=apptoken['v'];
			}
		}
	})
}

//触发input单击事件选择上传文件
function input(){
	document.getElementById('fileToUpload').click();
}
//选择完毕要上传的文件，把文件名推送到div显示出来
function getFilename(){
	document.getElementById('inputdiv').innerHTML=document.getElementById('fileToUpload').files[0].name;
}

    function uploadFile(tid) {
    	var maxsize=1024*1024*8;//限制最大上传不不超过8mb
        var checklogin = status;
        var file = document.getElementById('fileToUpload');
        if(tid && file.files[0]) {
            var fd = new FormData();  
            apptoken['tid']=tid;
            apptoken['act']='upload';
            fd.append('file', file.files[0]);
            for(var p in apptoken){
            fd.append(p, apptoken[p]);	
            }
        	filesize = file.files[0].size;
        	if(filesize>maxsize){
        	alert('上传文件不能超过'+maxsize+'MB;请压缩后上传。');
        	return false;
        	}
        	var fileName = file.files[0].name.substring(file.files[0].name.lastIndexOf(".")+1).toLowerCase();

	        if(fileName !="doc" && fileName !="pdf" && fileName !="docx" && fileName !="ppt" && fileName !="pptx"){
	        	alert('上传后缀名为doc/pdf/docx/ppt/pptx类型的文件');
	        	return false;
	        }
            var xhr = new XMLHttpRequest();
            w=plus.nativeUI.showWaiting("开始上传...");//进度信息
            xhr.upload.addEventListener("progress", uploadProgress, false);  
            xhr.addEventListener("load", uploadComplete, false);  
            xhr.addEventListener("error", uploadFailed, false);  
            xhr.addEventListener("abort", uploadCanceled, false);  
            xhr.open("POST", home.hos+'/resume/admin');  
            xhr.send(fd);
        } else {  
            swal({     
                title: "请选择要上传的文件",     
                text: "",     
                type: "warning"});
        }  
    }  
  function swal(evt){
  	//返回信息输出
  	alert(evt.title+evt.text);
  }
    function uploadProgress(evt) {
        if(evt.lengthComputable) {  
            var percentComplete = Math.round(evt.loaded * 100 / evt.total);  
			w.setTitle("已上传"+percentComplete.toString()+"%");//上传进度
        } else {  
            swal({title:"上传失败",text:evt.target.responseText,type:"warning"}); 
        }  
    }  
  
    function uploadComplete(evt) {
    	w.close();
        /* 服务器端返回响应时候触发event事件*/  
//      alert(evt.target.responseText);  
		swal({title:"上传成功",text:evt.target.responseText,type:"warning"});  
		    }  
  
    function uploadFailed(evt) {  
        swal({title:"传输过程出现错误",text:"",type:"warning"});  
    }  
  
    function uploadCanceled(evt) {  
        swal({title:"传输已取消",text:"",type:"warning"});  
    }  
  </script>